﻿using NB.MGJ.Common.MVC;
using NB.MGJ.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NB.MGJ.Web.Controllers
{
    public partial class CodeManageController : BaseController
    {

        public ActionResult List_V()
        {
            return View();
        }


        public ActionResult RecallAdd(CodeManage_CodeRelate model)
        {
            ViewData["CodeBatch"] = _CodeRelateService.GetGenCodeBatchList(LogOnUser.EnterpriseId, 0);
            return View();
        }

        public ActionResult GetCodeRecallPageList (int pageIndex = 1, int pageSize = 10, int action = 2)
        {

            PagerModel pm = new PagerModel();
            pm.Page = pageIndex;
            pm.PageSize = pageSize;

            var pageList = _CodeRelateService.GetCodeRelatePageList(ref pm, LogOnUser, action);
            return Json(pageList, JsonRequestBehavior.AllowGet);

        }




        public ActionResult ReList(CodeManage_CodeRelate model)
        {
            if (model != null)
            {
                string str = LogOnUser.ECode + model.CodeBatch;
                model.EnterpriseId = LogOnUser.EnterpriseId;
                var result = _CodeRelateService.DistributorList(str, model);
                //return Json(result);
                ViewBag.data=result;
                return View();
            }
            else
            {
                 CodeManage_GenCode gencode=new CodeManage_GenCode();
                 ViewBag.data = gencode;
                return View();
            }
      
        }
        //查看物流码
        public ActionResult LookWlCode(string formCode,string codeBatch)
        {
            if (!string.IsNullOrEmpty(formCode))
            {
                string tableName = "nbcodemain.antifake_digitcode" + LogOnUser.ECode + codeBatch;
                return Json(_CodeRelateService.LookDetail(formCode, tableName));
            }
            return Json("无数据");
        }

        public ActionResult RecallSave (CodeReCallModel CodeReCallModel)
        {
             CodeManage_CodeRelate model=new CodeManage_CodeRelate();
             model=CodeReCallModel.Model;

            int CodeEnterpriserId=_CodeCommonService.GetTableEnterpriseId(LogOnUser.EnterpriseId);

            var firstOrDefault=_CodeCommonService.GetCodeBatchFirstOrDefaultCodeModel(LogOnUser.EnterpriseId,CodeReCallModel.Model.CodeBatch);
         
            model.ProductId=Convert.ToInt32(firstOrDefault.ProductId);
            model.ProductBatchId=firstOrDefault.ProductBatchId;
            model.EnterpriseId = CodeEnterpriserId;
            model.ChangeDate=DateTime.Now;

            var result = _codeManageService.CodeRecall(CodeReCallModel);

  
            return Json(result);
        }


        public ActionResult antifleeing_distributorrecalllogList ()
        {
           //int DistributorId=  LogOnUser.Distributor;
           //DistributorId=122;
           //var list=_codeManageService.GetRecallListByDistributorId(DistributorId);

           //ViewBag.list=list;
           return View();
        }

        public ActionResult GetCodeRecallDetailPageList (int pageIndex = 1, int pageSize = 10)
        {
            PagerModel pm = new PagerModel();
            pm.Page = pageIndex;
            pm.PageSize = pageSize;

            var pageList = _CodeRelateService.GetCodeRecallDetailPageList(ref pm, LogOnUser);
            return Json(pageList, JsonRequestBehavior.AllowGet);
    
        }

        public ActionResult UpdateDistributorRecallLogStatus (int Id)
        {
           var result=  _codeManageService.UpdateDistributorRecallLogStatus(Id);
           return Json(result);
        }




    }
}